<template>
	<view class="content">
		<view class="wid100 dis disAl" style="height: 120rpx;">
			<view class="wid90 mar hei80 borRad40 dis disAl disJuC" style="background-color: #EEEEEE;">
				<view class="dis disAl disJuC" style="width: 13%;">
					<uni-icons type="search" size="35rpx" color="#AFB6B1"></uni-icons>
				</view>
				<input class="wid80" v-model="suosou" @input="suosouInput" placeholder="请输入搜索内容" placeholder-style="color: #AFB6B1;"/>
			</view>
		</view>
		<view class="wid100 dis" style="height: calc(100vh - 120rpx);">
			<scroll-view class="wid20 hei100" style="background-color: #EEEEEE;" scroll-y="true">
				<block v-for="(item,index) in list" :key="index">
					<view class="wid100 dis disAl disJuC foSi30 fowe600 poRel" @click="xuanClick(index)"
						style="min-height: 116rpx;" :class="xuan == index?'bacFFF':''">
						<view class="wid90 textCen">{{item.name}}</view>
						<view v-if="xuan == index" class="poAbs hei100" style="width: 6rpx;background-color: #37BCC3;left: 0;top: 0;"></view>
					</view>
				</block>
				<view style="height: 50rpx;"></view>
			</scroll-view>
			<scroll-view class="wid80 hei100" scroll-y="true" @scrolltolower="lower">
				<view style="height: 1rpx;"></view>
				<block v-for="(item,index) in list1" :key="index">
					<view class="wid85 mar mar-top30 dis disAl" @click="tiaozhuan('/pages/toiletries/commodity?id='+item.id)">
						<view class="wid25" style="height: 115rpx;" >
							<image :src="url+item.pic.split(',')[0]" class="hei100" style="width: 115rpx;"></image>
						</view>
						<view style="width: 75%;">
							<view class="foSi25">{{item.name}}</view>
							<view class="foSi25 mar-top10" style="color: #37BCC3;">¥{{item.price}}</view>
							<view class="dis disAl disJuB">
								<view class="foSi18" style="color: #969696;">已售{{item.sell_num}}</view>
								<image src="../../static/gwowuche.png" style="width: 39rpx;height: 39rpx;"></image>
							</view>
						</view>
					</view>
					<view class="wid90 mar mar-top30" style="border-bottom: 1rpx dashed #E1DFDF;"></view>
				</block>
				<view style="height: 50rpx;"></view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				url: this.global.url,
				list: [],
				last_page: 0,
				page: 1,
				list1: [],
				timer: null,
				suosou: '',
				xuan: 0
			}
		},
		onLoad() {
			this.getList()
		},
		onShow(){
		},
		methods: {
			xuanClick(index){
				if(this.xuan != index){
					this.xuan = index
					this.page = 1
					this.list1 = []
					this.getList1()
				}
			},
			suosouInput: function(event) {
				var that = this
				if (that.timer !== null) clearTimeout(that.timer)
				that.timer = setTimeout(() => {
					that.suosou = event.target.value
					console.log(that.suosou)
					that.page = 1
					that.getList1()
				}, 1000)
			},
			lower(e) {
				if(this.last_page > this.page){
					this.page++
					this.getList1()
				}
			},
			getList1() {
				var that = this;
				uni.request({
					url: that.global.url + '/api/qianyu_petrol/gasstation_goods',
					method: "POST",
					header: {
						'site-id': that.global.site_id,//自定义请求头信息
						'token': uni.getStorageSync('token')
					},
					data: {
						is_type: 0,
						page: that.page,
						limit: 10,
						type_id: that.list[that.xuan].id,
						search: that.suosou
					},
					success(res) {
						let result = res.data
						console.log(result)
						if (result.code == 1) {
							that.last_page = result.data.last_page
							if(that.page == 1){
								that.list1 = result.data.data
							}else{
								that.list1 = that.list1.concat(result.data.data)
							}
							
						}
					}
				})
			},
			getList() {
				var that = this;
				var list = [{'id': '',"site_id": 100000,"name": "全部"}]
				uni.request({
					url: that.global.url + '/api/qianyu_petrol/gasstation_goods_type',
					method: "POST",
					header: {
						'site-id': that.global.site_id,//自定义请求头信息
						'token': uni.getStorageSync('token')
					},
					data: {},
					success(res) {
						let result = res.data
						console.log(result)
						if (result.code == 1) {
							that.list = list.concat(result.data)
							that.page = 1
							that.getList1()
						}
					}
				})
			},
			tiaozhuan(url){
				uni.navigateTo({
					url: url
				})
			}
		}
	}
</script>

<style>
	.content {}
	
</style>
